package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.GoodsHistoryDetail;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.GoodsHistoryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 历史商品记录Controller
 * @author 田沛凌
 * @time 2017年7月6日 下午4:30:52
 */
@RestController
@RequestMapping(value = "/goodsHistoryDetail", method = RequestMethod.POST)
public class GoodsHistoryController {
	
    private GoodsHistoryDetailService goodsHistoryDetailService;
    @Autowired
    public void setGoodsHistoryDetailService(GoodsHistoryDetailService goodsHistoryDetailService) {
        this.goodsHistoryDetailService = goodsHistoryDetailService;
    }

    /**
     * 批量增加历史商品
     * @param idStr 上架商品ID集合
     */
    @RequestMapping("/addGoodsHistoryDetail")
    public BaseResponse addGoodsHistoryDetail(String idStr){
        goodsHistoryDetailService.addGoodsHistoryDetail(idStr);
        return AppResponse.OK;
    }
    /**
     * 获取历史商品信息
     * @param id 历史商品ID
     */
    @RequestMapping("/getGoodsHistoryDetail")
    public BaseResponse getGoodsHistoryDetail(Long id){
        GoodsHistoryDetail goodsHistoryDetail = goodsHistoryDetailService.get(id);
        return new AppResponse(goodsHistoryDetail);
    }
    /**
      * 删除历史商品
      * @param id;
      */
    @RequestMapping("/delGoodsHistoryDetail")
    public BaseResponse delGoodsHistory(Long id) {
        goodsHistoryDetailService.del(id);
        return AppResponse.OK;
    }
    /**
     * 查询历史商品记录(分页)
     * @param goodsHistoryDetail;
     */
    @RequestMapping("/pageGoodsHistoryDetail")
    public BaseResponse pageGoodsHistory(GoodsHistoryDetail goodsHistoryDetail) {
        List<GoodsHistoryDetail> listGoodsHistory = goodsHistoryDetailService
                .list(goodsHistoryDetail);
        return new AppResponse(new PageInfo<>(listGoodsHistory));
    }
}
